package com.lianboke.link.ad.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lianboke.link.ad.R;
import com.lianboke.link.ad.beans.AccountRecordModel;

import java.util.ArrayList;
import java.util.List;

/**
 * 提现记录适配器
 * Created by admin on 2018/1/9.
 */

public class AccountRecordAdapter extends BaseAdapter {


    private Context context;

    private List<AccountRecordModel> datas = new ArrayList<AccountRecordModel>();

    public AccountRecordAdapter(Context context) {
        this.context = context;
    }

    /**
     * s
     * @param data
     */
    public void setOrderDatas(List<AccountRecordModel> data){
        if(datas!=null){
            datas.clear();
        }
        datas.addAll(data);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if(datas==null || datas.isEmpty()){
            return 0;
        }else {
            return datas.size();
        }
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView==null){
            viewHolder = new ViewHolder();
            convertView =  LayoutInflater.from(context).inflate(R.layout.account_record_item_layout,null);
            viewHolder.setmTvRecordStatus(convertView.findViewById(R.id.tv_record_status));
            viewHolder.setmTvRecordDate(convertView.findViewById(R.id.tv_record_time));
            viewHolder.setmTvRecordMoney(convertView.findViewById(R.id.tv_record_money));
            convertView.setTag(viewHolder);
        }else{
            viewHolder =(ViewHolder) convertView.getTag();
        }
        AccountRecordModel accountRecordModel=(AccountRecordModel)getItem(position);
        viewHolder.getmTvRecordDate().setText(accountRecordModel.getDate());
        viewHolder.getmTvRecordMoney().setText(accountRecordModel.getDrawmoney());
        viewHolder.getmTvRecordStatus().setText(accountRecordModel.getStatuContent());

        return convertView;
    }

    /**
     *view 对象
     */
    public class ViewHolder {
        private TextView mTvRecordStatus;
        private TextView mTvRecordDate;
        private TextView mTvRecordMoney;

        public ViewHolder() {
        }

        public TextView getmTvRecordStatus() {
            return mTvRecordStatus;
        }

        public void setmTvRecordStatus(TextView mTvRecordStatus) {
            this.mTvRecordStatus = mTvRecordStatus;
        }

        public TextView getmTvRecordDate() {
            return mTvRecordDate;
        }

        public void setmTvRecordDate(TextView mTvRecordDate) {
            this.mTvRecordDate = mTvRecordDate;
        }

        public TextView getmTvRecordMoney() {
            return mTvRecordMoney;
        }

        public void setmTvRecordMoney(TextView mTvRecordMoney) {
            this.mTvRecordMoney = mTvRecordMoney;
        }
    }


}
